import { AccountPayment } from './account-payment.entity'
import {
  PrimaryGeneratedColumn,
  OneToOne,
  Column,
  Entity,
  UpdateDateColumn,
  CreateDateColumn,
  ManyToOne,
  JoinColumn
} from 'typeorm'
import { Account } from './account.entity'

@Entity()
export class AccountWechat {
  @PrimaryGeneratedColumn()
  id: number

  // 很多微信账号有同一个account
  @ManyToOne(type => Account, account => account.wechats)
  account: Account

  /**
   * 一个公众号有一个支付
   */
  @OneToOne(type => AccountPayment, payment => payment.accountWechat, {
    eager: true
  })
  @JoinColumn()
  payment: AccountPayment

  @Column({
    comment: '公众号名称'
  })
  name: string

  @Column({
    comment: '头像'
  })
  avatar: string

  @Column({
    comment: '二维码'
  })
  qrcode: string

  @Column({
    comment: '引导关注地址'
  })
  subscribeurl: string

  @Column({
    comment: '消息加解密密钥'
  })
  encodingaeskey: string

  @Column({
    comment: '令牌'
  })
  token: string

  @Column({
    comment: '身份标识'
  })
  appId: string

  @Column({
    comment: '身份密钥'
  })
  appSecret: string

  @UpdateDateColumn({
    comment: '更新时间'
  })
  updateDate: number

  @CreateDateColumn({
    comment: '创建时间'
  })
  createDate: number
}
